package session.stateless;

import entity.Employee;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class ContactSessionBean implements ContactSessionBeanLocal {

    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public List<Employee> getContacts(String userId) { //get contact list
        ArrayList al = new ArrayList();

        Query query = entityManager.createQuery("SELECT e FROM Employee e WHERE e.userId <> :inuserId ORDER BY e.userId ASC");
        query.setParameter("inuserId", userId);

        for (Object o : query.getResultList()) {
            Employee employee = (Employee) o;

            al.add(employee);
        }
        System.out.println(userId + " - " + al.size());
        return al;
    }

    @Override
    public Employee getContact(String userId) { //get contact
        Employee employee = entityManager.find(Employee.class, userId);

        return employee;
    }
}
